package com.lingx.model.impl.executor;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.lingx.model.IContext;
import com.lingx.model.IExecutor;
import com.lingx.model.IPerformer;
import com.lingx.service.InterpretService;
import com.lingx.service.ModelService;
import com.lingx.web.api.IApi;
@Component
public class ComboExecutor implements IExecutor,Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5142606489758426658L;
	@Resource
	private JdbcTemplate jdbcTemplate;
	@Resource
	private ModelService modelService;
	@Override
	public String getId() {
		return "ComboExecutor";
	}

	@Override
	public String getCode() {
		return "ComboExecutor";
	}

	@Override
	public String getName() {
		return "ComboExecutor";
	}

	@Override
	public String getIconCls() {
		return "ComboExecutor";
	}

	@Override
	public Boolean getLeaf() {
		return true;
	}

	@Override
	public String getModelType() {
		return "ComboExecutor";
	}

	@Override
	public void setId(String id) {
		
	}

	@Override
	public void setAuthor(String author) {
		
	}

	@Override
	public void setLastModifyTime(String lastModifyTime) {
		
	}

	@Override
	public Object execute(Map<String, Object> params,IContext context, IPerformer performer) throws Exception {
		Map<String,Object> ret=IApi.getRetMap();
		String p1=IApi.getParamString(params, "p1", "");
		String textField=this.modelService.getTextField(context.getEntity()).get(0);
		String sql="select "+textField+" text,id value from "+context.getEntity().getTableName()+" where "+textField+" like ? order by "+textField+" asc limit 50";
		//System.out.println(sql);
		List<Map<String,Object>> rows=this.jdbcTemplate.queryForList(sql,"%"+p1+"%");
		ret.put("data", rows);
		return ret;
	}

}
